package com.tywj.buscustomerapp.view.activity.tour;

import android.support.annotation.NonNull;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.tywj.buscustomerapp.R;
import com.tywj.buscustomerapp.utils.myadapter.CommonRcvAdapter;
import com.tywj.buscustomerapp.utils.myadapter.RcvAdapterWrapper;
import com.tywj.buscustomerapp.utils.myadapter.item.AdapterItem;
import com.tywj.buscustomerapp.view.activity.BaseActivity;
import com.tywj.buscustomerapp.view.item.ScenicTicketItem;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class ScenicTicketActivity extends BaseActivity {
    @BindView(R.id.head_left)
    ImageView back;
    @BindView(R.id.head_title)
    TextView title;
    @BindView(R.id.recycler)
    RecyclerView recyclerView;
    private View header;
    private EditText editText;
    private RcvAdapterWrapper raw;
    private CommonRcvAdapter<String> adapter;
    private List<String> list  = new ArrayList<>();

    @Override
    protected int getContentId() {
        return R.layout.activity_scenic_ticket;
    }

    @Override
    protected void initWidget(Bundle savedInstanceState) {
        super.initWidget(savedInstanceState);
        title.setText("景区门票");
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setStackFromEnd(false);
        recyclerView.setLayoutManager(layoutManager);
        adapter = new CommonRcvAdapter<String>(list) {
            @NonNull
            @Override
            public AdapterItem createItem(Object type) {
                return new ScenicTicketItem();
            }
        };
        raw = new RcvAdapterWrapper(adapter,layoutManager);
        header = View.inflate(this,R.layout.scenic_ticket_head_layout,null);
        editText = header.findViewById(R.id.edit);
        recyclerView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
        recyclerView.setFocusable(true);
        recyclerView.setFocusableInTouchMode(true);
        recyclerView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                v.requestFocusFromTouch();
                return false;
            }
        });
        raw.setHeaderView(header);
        recyclerView.setAdapter(raw);
    }

    @Override
    protected void initData() {
        super.initData();
        for (int i = 0; i < 30; i++) {
            list.add("i:"+i);
        }
        adapter.setData(list);
        adapter.notifyDataSetChanged();
    }

    @Override
    protected void initClick() {
        super.initClick();
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }
}
